package com.zhkc.wisdom.commom.mybatis.mate;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.zhkc.wisdom.commom.mybatis.mate.handler.DataScopeHandler;
import com.zhkc.wisdom.common.configure.constant.ConfigureConstant;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * Project: mc Package: com.ttsh.mc.config.mybatisplus Description: ...
 * <p>
 *
 * @author Mars Data: 2018/5/3 下午4:16
 */

@Slf4j
@Configuration
@ConditionalOnProperty(prefix = ConfigureConstant.ZHKC_PROPERTIES_PREFIX + ".mybatis.mate", name = "enabled", havingValue = "true", matchIfMissing = false)
public class MybatisMateAutoConfiguration {
    @PostConstruct
    public void init() {
        log.info("init MybatisMateAutoConfiguration...");
    }

    @Bean
    @Primary
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new DataPermissionInterceptor(new DataScopeHandler()));
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL));
        return interceptor;
    }
}
